package com.quyunshuo.module.home.dialog

import android.os.Bundle
import android.util.Log
import android.view.Gravity
import com.quyunshuo.module.home.databinding.DialogConcentrationBinding
import com.quyunshuo.module.home.util.dp

class ConcentrationDialog : BaseDialog<DialogConcentrationBinding>() {
    companion object {
        fun newInstance(): ConcentrationDialog {
            return ConcentrationDialog()
        }
    }

    private var time:Int = 5

    private var callback: ((Int) -> Unit?)? = null
    fun setCallback(callback: (Int) -> Unit) {
        this.callback = callback
    }

    override fun getGravity(): Int {
        return Gravity.BOTTOM
    }

    override fun createViewBinding(): DialogConcentrationBinding {
        return DialogConcentrationBinding.inflate(layoutInflater)
    }

    override fun init(savedInstanceState: Bundle?) {
        binding.comfirm.setOnClickListener {
            dismissAllowingStateLoss()
            callback?.invoke(time)
        }
        binding.timeLineView.setOnScaleChangeListener {
            time = it.toInt()
            binding.time.text = "$time 分钟"
            Log.d("wenlong", "setOnMinuteChangedListener: $time")
        }
//        binding.timeLineView.setOnMinuteChangedListener {
//            time = it
//            binding.time.text = "$it 分钟"
//
//            Log.d("wenlong", "setOnMinuteChangedListener: $it")
//        }
    }


    override fun getWidth(): Int {

        if (isTabletDevice(resources.configuration)) {
            return 600.dp
        } else {
            return 360.dp

        }

    }

    override fun cancel(): Boolean {
        return true
    }

}